package com.splic.common.config;

import com.github.binarywang.wxpay.config.WxPayConfig;
import com.github.binarywang.wxpay.service.WxPayService;
import com.github.binarywang.wxpay.service.impl.WxPayServiceImpl;
import me.chanjar.weixin.common.service.WxOAuth2Service;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.api.impl.WxMpOAuth2ServiceImpl;
import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl;
import me.chanjar.weixin.mp.config.WxMpConfigStorage;
import me.chanjar.weixin.mp.config.impl.WxMpDefaultConfigImpl;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

//@Configuration
public class WechatMpConfig {


//    @Bean
    public WxMpConfigStorage wxMpConfigStorage(){
        WxMpDefaultConfigImpl wxMpConfigStorage = new WxMpDefaultConfigImpl();
        wxMpConfigStorage.setAppId(WechatConfig.appId);
        wxMpConfigStorage.setSecret(WechatConfig.secret);
        return wxMpConfigStorage;
    }

//    @Bean
    public WxMpService wxMpService(){
        WxMpService wxMpService = new WxMpServiceImpl();
        wxMpService.setWxMpConfigStorage(wxMpConfigStorage());
        return wxMpService;
    }

//    @Bean
    public WxOAuth2Service wxOAuth2Service(){
        WxMpOAuth2ServiceImpl auth2Service = new WxMpOAuth2ServiceImpl(wxMpService());
        return auth2Service;
    }

//    @Bean
    public WxPayService wxPayService(){
        WxPayConfig wxPayConfig = new WxPayConfig();
        wxPayConfig.setMchId(WechatConfig.mchId);
        wxPayConfig.setAppId(WechatConfig.appId);
        wxPayConfig.setMchKey(WechatConfig.mchKey2);
        wxPayConfig.setApiV3Key(WechatConfig.mchKey3);
        wxPayConfig.setNotifyUrl(WechatConfig.notifyUrl);
        WxPayService wxPayService = new WxPayServiceImpl();
        wxPayService.setConfig(wxPayConfig); //微信配置信息
        return wxPayService;
    }
}